package com.atguigu.lease.common.springmvc;

import com.atguigu.lease.common.exceptions.LeaseException;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.common.result.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandlers {
    @ExceptionHandler( Exception.class)
    public Result<String> exceptionHandler(Exception e){
        e.printStackTrace();
        String msg = e.getMessage();
        return  Result.fail();
    }
    @ExceptionHandler(LeaseException.class)
    public Result LeaseExceptionHandler(LeaseException e){
        e.printStackTrace();
        ResultCodeEnum resultCodeEnum =e.getResultCodeEnum();
        return Result.build(null, resultCodeEnum);


    }

}
